/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
  require('ui-table');
  app.useModule("ui.table");
    var datepicker = require('datepicker');
    var toastr =require('toastr');
    app.controller('appointCtrl', ['$scope','$http',function ($scope, $http) {
        $scope.ctrlScope=$scope;
      $scope.orderParams = {
          url: "/admin/lottery/lotteryNominatorList"
      };
      datepicker($scope);
        //全局查询
        $scope.search = function() {
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
        };

        //全局查询重置
        $scope.reset=function(){
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.ajaxParam={};
            $scope.orderParams.reload();
        };

        $scope.addOrderModal=function(){
            $scope.addModal=!$scope.addModal;
        }

        $http({
            method: 'POST',
            url: "/admin/lottery/goodsRewardList",
            data:{
                activeName:'礼品转盘',
                pageSize:99,
            },
        }).success(function(data) {
            console.info(data);
            $scope.object=data.list;

        }).error(function(data) {
        });

        $scope.addAppoint=function(){
            var param={
                mobile:$scope.ctrlScope.add.mobile,
                goodsId:$scope.ctrlScope.add.goodsId
            }
            console.info(param);
            $http({
                method: 'POST',
                url: "/admin/lottery/addNominator",
                data:param,
            }).success(function(data) {
                if(data.result=="success"){
                    toastr.success("提交成功");
                    $scope.addModal=!$scope.addModal;
                    $scope.orderParams.reload();
                }else{
                    if(data.messageCode=="sys.error"){
                        toastr.error("系统异常");
                    }else{
                        toastr.error(data.messageText);
                    }
                }

            }).error(function(data) {
            });

        }


    }]);
});